package com.ce.pms.customer.service.impl;

import java.util.ArrayList;
import java.util.List;
import com.ce.pms.charge.dao.IBankCollectionDao;
import com.ce.pms.charge.vo.AccountVO;
import com.ce.pms.charge.vo.BankAccountVO;
import com.ce.pms.common.model.SysInfo;
import com.ce.pms.common.model.SysrefcodeDO;
import com.ce.pms.common.web.ICacheManage;
import com.ce.pms.customer.model.ClientDO;
import com.ce.pms.customer.model.ClientRHouseDO;
import com.ce.pms.customer.model.IndividualDO;
import com.ce.pms.customer.model.OrganizationDO;
import com.ce.pms.customer.model.ParticipantDO;
import com.ce.pms.customer.model.ProRightDO;
import com.ce.pms.customer.model.RelationTypeDO;
import com.ce.pms.customer.service.IOwnerService;
import com.ce.pms.customer.vo.CustomerHouseVO;
import com.ce.pms.customer.vo.CustomerVO;
import com.ce.pms.customer.vo.IndividualVO;
import com.ce.pms.customer.vo.OrganizationVO;
import com.ce.pms.customer.vo.ProRightVO;
import com.ce.pms.exception.BusinessException;
import com.ce.pms.house.model.CoalitionHouseDomain;
import com.ce.pms.house.model.HouseDomain;
import com.ce.util.BlankUtil;

/**
 *
 * 功能描述: OwnerServiceImpl 业主服务类
 * <p>版权所有：中企动力
 * <p>未经本公司许可，不得以任何方式复制或使用本程序任何部分
 *
 * @author  付湘辉
 * Created on：  2008-05-22
 *
 */
public class OwnerServiceImpl extends CustomerServiceImpl implements
		IOwnerService {

	private IBankCollectionDao bankCollectionDao;
	/**
	 * 当次新增的业主数量（在新增，修改业主时用到）
	 */
	private int cur_add_owner_count = 0;

	public void setBankCollectionDao(IBankCollectionDao bankCollectionDao) {
		this.bankCollectionDao = bankCollectionDao;
	}

	/**
	 *
	 * 功能描述: 添加一个业主。
	 * <ol>
	 * <li>在业务上，一个业主可以有多个住房，一套住户也可有多个业主。</li>
	 * <li>业主可以是个人或组织。</li>
	 * <li>组织类型的业主包含有法人代表和委托代理人。</li>
	 * </ol>
	 * <ul>
	 *
	 * <li>注意：</li>
	 * <li>此方法重写父类方法以实现自身逻辑</li>
	 * <li>添加业主内容包括添加其住房信息和自身详细资料。</li>
	 * <li>组织类型的业主包含有法人代表和委托代理人，在添加住户时，同时添加这些信息及它们的关系信息。</li>
	 * </ul>
	 *
	 * @author 付湘辉
	 * Created on:2008-6-10
	 *
	 * 修改原因：
	 * @param houseList 业主住房信息列表
	 * @param customerList 业主信息列表
	 * @return String "true" 表示成功  "false" 表示失败
	 */
	@Override
	public String addCustomer(List<CustomerHouseVO> houseList, List<CustomerVO> customerList) {
        //检查参数
        this.checkCustomerInfo(houseList, customerList);
        this.cur_add_owner_count=0;//置当次新增业主数为0
        try{
	        ClientDO clientDO=null;
	        SysrefcodeDO clientTypeDO = super.sysrefcodeDao.getSysrefCodesByCode(SysrefcodeDO.CS_CLIENT_CLIENT_TYPE_CODE, SysrefcodeDO.CLIENT_TYPE_OWNER);

	        //处理业主房屋信息的添加和修改
	        this.dealOwnerHouse(houseList);

	        for(CustomerHouseVO customerHouseVO : houseList){

		        for(CustomerVO customerVO:customerList){

					if(CustomerVO.INDIVIDUAL_CODE.equals(customerVO.getParticipantTypeCode())){
						//处理个人业主
						this.dealIndividualOwner(clientTypeDO, customerHouseVO, customerVO);
					}else if(CustomerVO.ORGNIZATION_CODE.equals(customerVO.getParticipantTypeCode())) {
						//处理个组织业主
						this.dealOrganizationOwner(clientTypeDO, customerHouseVO, customerVO);
					}else{
						throw new BusinessException("customer:participant_type_unknown_exception",BusinessException.ERROR);
					}

					if(ICacheManage.DELETE.equals(customerVO.getOpratorStatus())
							|| ICacheManage.DELETE.equals(customerHouseVO.getOpratorStatus())){
						//执行删除操作
						this.toDeleteOperation(clientTypeDO, customerHouseVO, customerVO);
					}else if (ICacheManage.UNSAVE.equals(customerHouseVO.getHasSave())&& !BlankUtil.isBlank(customerVO.getParticipantId())) {
						clientDO = super.clientDao.queryClientByParticipantAndClientType(customerVO.getParticipantId(), clientTypeDO.getId());
						this.buildClientRHouse(customerHouseVO, clientDO);
					}

				}//end for(CustomerVO customerVO:customerList)

	        }//end for(CustomerHouseVO customerHouseVO : houseList)
        } catch (BusinessException be){
        	throw be;
        } catch (Exception e){
        	throw new BusinessException("customer:owner_addowner_fail_exception",
        						BusinessException.FAILURE);
        } finally {
        	this.cur_add_owner_count=0;
        }

		return "true";
	}

	@Override
	public String editCustomer(List<CustomerHouseVO> houseList, List<CustomerVO> customerList) {
		return this.addCustomer(houseList, customerList);
	}

	/**
	 * 功能描述: 判断是否能够添加划款银行帐号,
	 * 如果在参数customerHouseVO中的划款银行帐号信息完整则返回true <br>
	 * 判断帐号信息完整的依据是１1：银行id 2:银行帐号
	 * @param customerHouseVO 客户房屋信息，其中保存有要新增的划款银行帐号信息
	 * @return
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-9-2  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public Boolean canAddBankAccount(CustomerHouseVO customerHouseVO){

		if (BlankUtil.isBlank(customerHouseVO.getBankId())
				|| BlankUtil.isBlank(customerHouseVO.getBankNumber())) {
			return false;
		}
		return true;
	}

	@Override
	public IndividualVO findIndividualById(Long participantId) {
		return super.findIndividualById(participantId);
	}

	@Override
	public OrganizationVO findOrganizationById(Long participantId) {
		return super.findOrganizationById(participantId);
	}

	/**
	 * 功能描述: 通过房屋id查询得到所有当前有效业主信息 <br>
	 * @param houseId
	 * @return
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-8-19  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public List<CustomerVO> getAllOwnerByHouseId(Long houseId){
		super.checkParameterIsNull(houseId, "common:parameters_null_exception,ID");
		ProRightDO pro = super.proRightDao.getEffectiveProRightByHouseId(houseId);
		if (BlankUtil.isBlank(pro)) {
			return null;
		}

		return this.getAllOwnerByHouseId(houseId, pro.getProRightId());
	}

	/**
	 * 功能描述: 通过房屋id和产权id查询得到所有业主信息 <br>
	 * @param houseId
	 * @param proRightId
	 * @return
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-8-19  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public List<CustomerVO> getAllOwnerByHouseId(Long houseId,Long proRightId){
		super.checkParameterIsNull("common:parameters_null_exception,ID",houseId,proRightId);
		List<CustomerVO> list = new ArrayList<CustomerVO>();
		List<ParticipantDO> tmpList = super.clientRHouseDao.getAllOwnerByHouseId(houseId,proRightId);
		if (!BlankUtil.isBlank(tmpList)) {
			CustomerVO tmpV = null;
			for (ParticipantDO participantDO : tmpList) {
				if (participantDO instanceof IndividualDO) {
					tmpV=super.copyIndividualDOToIndividualVO((IndividualDO)participantDO);
					tmpV.setParticipantTypeCode(CustomerVO.INDIVIDUAL_CODE);
				}else if (participantDO instanceof OrganizationDO) {
					// 得到法人
					IndividualDO corporationDO = this.participantRelationDao
							.getOrganizationParticipant(participantDO.getParticipantId(),
														RelationTypeDO.RTYPE_ENTERPRISE_LEGAL);

					//得到委托/代理人
					IndividualDO consignerDO = this.participantRelationDao
							.getOrganizationParticipant(participantDO.getParticipantId(),
													RelationTypeDO.RTYPE_ENTERPRISE_PROXY);
					tmpV = super.copyDOToOrganizationVO((OrganizationDO) participantDO,
														corporationDO,
														consignerDO);
					tmpV.setParticipantTypeCode(CustomerVO.ORGNIZATION_CODE);
				}else{
					continue;
				}
				list.add(tmpV);
			}
		}
		return list;
	}

	/**
	 * 功能描述：通过产权房号获得的该房间的管理房及其相关的产权房
	 *
	 * @param houseNumber 房号
	 * @return List<CustomerHouseVO> 住房信息列表
	 */
	public List<CustomerHouseVO> getCustomerHouseList(String houseNumber){
		return super.getCustomerHouseList(houseNumber);
	}

	/**
	 *
	 * 功能描述: 通过参与人(业主)id得到其所有房屋信息VO对象列表
	 *
	 * @author 付湘辉
	 * Created on:2008-6-11
	 *
	 * 修改原因：
	 * @param participantId
	 * @return List<CustomerHouseVO> 房屋信息VO对象列表
	 */
	public List<CustomerHouseVO> getOwnerHouseListById(Long participantId){

		super.checkIsNull(participantId);

		SysrefcodeDO clientType = this.sysrefcodeDao.getSysrefCodesByCode(SysrefcodeDO.CS_CLIENT_CLIENT_TYPE_CODE, SysrefcodeDO.CLIENT_TYPE_OWNER);

		return super.getCustomerHouseListById(participantId, clientType);

	}

	/**
	 *
	 * 功能描述: 根据参与人ID查询业主住房信息分页对象
	 *
	 * @author 付湘辉
	 * Created on:2008-6-3
	 *
	 * 修改原因：
	 * @param participantId
	 * @param currentPage
	 * @param pageSize
	 * @roseuid 483117990196
	 * @return Page
	 */
//	public Page queryOwnerHouseListByPage(Long participantId, Integer currentPage,
//			Integer pageSize) {
//		Page page = null;
//
//		page = ownerDao.queryClientRHouseListByPage(participantId, currentPage,
//				pageSize);
//
//		CustomerHouseVO customerHouseVO = null;
//		List list = null;
//		List list2 = null;
//		if (page!= null && !page.isEmpty()) {
//			list = page.getResult();
//			list2 = new ArrayList();
//			ClientRHouseDO clientRHouseDO = null;
//			for (int i = 0; i < list.size(); i++) {
//
//				clientRHouseDO = (ClientRHouseDO) list.get(i);
//				customerHouseVO = new CustomerHouseVO();
//				// 需要增加得到银行帐号的代码
//				customerHouseVO.setHouseId(clientRHouseDO.getHouse().getKeyword());
//				customerHouseVO.setHouseNumber(clientRHouseDO.getHouse()
//						.getHouseNumber());
//				customerHouseVO.setHousePropertyNo(clientRHouseDO.getProRight()
//						.getProRightNO());
//				list2.add(customerHouseVO);
//			}
//			page.setResult(list2);
//		}
//		return page;
//	}

	/**
	 *
	 * 功能描述: 查询除指定房号外的其它房屋中,所关联的指定合同号或者产权号的数量
	 * 注意:参数contactNO 和 proRightNO 有一个应该为空
	 *
	 * @author 付湘辉
	 * Created on:2008-6-26
	 *
	 * 修改原因：
	 * @param houseNumber
	 * @param contactNO
	 * @param proRightNO
	 * @return Integer 返回结果
	 */
	public Integer getProRightCountByHouse(String houseNumber,String contactNO,String proRightNO){
		Integer result = null;
		if (BlankUtil.isBlank(houseNumber)) {
			return null;
		}

		HouseDomain house = super.houseService.getHouseByNumber(houseNumber);
		if (BlankUtil.isBlank(house)) {
			return null;
		}

		result = super.proRightDao.getProRightCountByHouse(house, contactNO, proRightNO);

		return result;
	}

	/**
	 *
	 * 功能描述: 建立业主房屋产权的关系
	 *
	 * @author 付湘辉
	 * Created on:2008-6-10
	 *
	 * 修改原因：
	 * @param customerHouseVO
	 * @param clientDO
	 * @return ClientRHouseDO 返回结果
	 */
	protected ClientRHouseDO buildClientRHouse(CustomerHouseVO customerHouseVO, ClientDO clientDO) {

		ClientRHouseDO clientRHouseDO
		   = super.clientRHouseDao.getClientRHouseByHouseAndClient(customerHouseVO.getHouseId(), clientDO.getParticipantRoleId());

		if (BlankUtil.isBlank(clientRHouseDO)) {
			super.validateParticipantRoleInSameHouse(clientDO.getParticipant().getParticipantId(), customerHouseVO);
			clientRHouseDO = new ClientRHouseDO();

			//绑定客户
			clientRHouseDO.setClient(clientDO);

			HouseDomain house = super.flatDao.findById(customerHouseVO.getHouseId());

			//房屋状态是“未售”，则要将房屋改成“入伙中”的状态
			if (!BlankUtil.isBlank(house.getStatus())) {
				String houseStatus=house.getStatus().getValue();
				if (SysrefcodeDO.HM_HOUSE_HOUSE_STATUS_VALUE_NOTONSALE.equals(houseStatus)) {
					SysrefcodeDO status = super.sysrefcodeDao
                            .getSysrefCodesByCode(
                                    SysrefcodeDO.HM_HOUSE_HOUSE_STATUS_CODE,
                                    SysrefcodeDO.HM_HOUSE_HOUSE_STATUS_VALUE_INTHEOCCUPATION);
                    house.setStatus(status);
				}
			}
			//绑定房屋
			clientRHouseDO.setHouse(house);

			//关联产权
			ProRightDO proRightDO= super.proRightDao.getEffectiveProRightByHouseId(customerHouseVO.getHouseId());
			clientRHouseDO.setProRight(proRightDO);
			clientRHouseDO.setValidity(SysInfo.VALIDITY);

			// 如果房屋没有业主，将建立帐户
            if (canAddAccount(house, null)) {
            	AccountVO accVo = super.accountService.getCurrentAccountBy(proRightDO.getProRightId(), house.getKeyword());
            	if (BlankUtil.isBlank(accVo)) {
            		SysInfo sysInfo = super.createInfo(customerHouseVO.getCreator());
            		super.accountService.addAccount(house, proRightDO, sysInfo);
				}
            }

            super.clientRHouseDao.saveObject(clientRHouseDO);
            this.cur_add_owner_count++;
		}else if(BlankUtil.isBlank(clientRHouseDO.getProRight())){
			ProRightDO proRightDO = super.proRightDao.getEffectiveProRightByHouseId(customerHouseVO.getHouseId());
			if (!BlankUtil.isBlank(proRightDO)) {
				clientRHouseDO.setProRight(proRightDO);
				super.clientRHouseDao.updateObject(clientRHouseDO);
			}
		}
		return clientRHouseDO;
	}

	/** 功能描述:  <br>
	 * @param customerHouseVO
	 * @param proRightVO
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-9-2  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	*/
	private void addBankAccount(CustomerHouseVO customerHouseVO, ProRightVO proRightVO) {
		BankAccountVO bankAccount = new BankAccountVO();
		setBankAccountValues(customerHouseVO, proRightVO, bankAccount);
		super.bankAccountService.addBankAccount(bankAccount);
	}

	/**
	 *
	 * 功能描述: 添加或修改产权
	 * @see com.ce.pms.customer.dao.impl.ProRightDaoImpl#getEffectiveProRightByHouseId(Long)
	 * @author 许海堆
	 * Created on:2008-6-10
	 *
	 * 修改原因：
	 * @param customerHouseVO
	 * @return ProRightDO 产权DO
	 */
	private ProRightVO addOrEditProRight(CustomerHouseVO customerHouseVO) {
		ProRightVO proRightVo = super.proRightService.getEffectiveProRightByHouseId(customerHouseVO.getHouseId());
		if(BlankUtil.isBlank(proRightVo)){
			proRightVo = super.proRightService.assembleV2V(customerHouseVO);
			proRightVo.setChargeSelect(SysrefcodeDO.CONSTANTS_DIGITAL_ONE);
			proRightVo = super.proRightService.addProRight(proRightVo);
		} else {
			proRightVo.setContactNO(customerHouseVO.getHouseContractNumber());
			proRightVo.setProRightNO(customerHouseVO.getHousePropertyNo());
			proRightVo.setModifier(customerHouseVO.getCreator());
			proRightVo = super.proRightService.editProRight(proRightVo);
		}
		return proRightVo;
	}

	/** 功能描述: 房屋状态是“未售”的，或者“空置”并且没有业主时，返回true <br>
	 * @param house
	 * @param houseStatus
	 * @return
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-8-26  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	*/
	private boolean canAddAccount(HouseDomain house, String houseStatus) {
//		boolean res = SysrefcodeDO.HM_HOUSE_HOUSE_STATUS_VALUE_NOTONSALE.equals(houseStatus)
//		        || (SysrefcodeDO.HM_HOUSE_HOUSE_STATUS_NAME_VACANT.equals(houseStatus)
//		        && SysrefcodeDO.CONSTANTS_ZERO==super.clientRHouseDao.getAllOwnerByHouseId(house.getKeyword()).size());
//		return res;

		boolean res = SysrefcodeDO.CONSTANTS_ZERO==super.clientRHouseDao.getAllOwnerByHouseId(house.getKeyword()).size();

		return res;
	}

	/**
	 * 功能描述: 检查住户房屋列表是否为空，检查住户列表是否为空
	 *
	 * @author 付湘辉
	 * Created on:2008-6-20
	 *
	 * 修改原因：
	 * @param houseList
	 * @param customerList
	 * @return void 返回结果
	 */
	private void checkCustomerInfo(List<CustomerHouseVO> houseList, List<CustomerVO> customerList) {
		super.checkParameterIsNull(houseList, "customer:customer_house_null_exception");
		super.checkParameterIsNull(customerList, "customer:customer_baseinfo_null_exception");
	}

	/** 功能描述: 处理划款银行帐号，对于每一个房屋，
	 * 如果没有有效的划款银行帐号，而且VO中有完整的帐号信息，
	 * 则新增一个，如果这个房屋已存一个有效帐号，但没有做过出盘，
	 * 则用新的帐号覆盖旧的帐号信息，如果已出过盘，则将旧的帐号禁用，
	 * 新增一条新的帐号信息。 <br>
	 * @param customerHouseVO
	 * @param proRightVO
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-8-25  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	private void dealBankAccount(CustomerHouseVO customerHouseVO, ProRightVO proRightVO) {
		ProRightVO temp = new ProRightVO();
		//	合并记账则查询管理房的产权
		if (ProRightDO.CHARGE_SELECT_MERGER.equals(proRightVO.getChargeSelect())) {
			CoalitionHouseDomain cHouse = this.houseDao.getCoalition(customerHouseVO.getHouseId());
			ProRightDO proright = this.proRightDao.getEffectiveProRightByHouseId(cHouse.getKeyword());
			if (BlankUtil.isBlank(proright)) {
				return;
			}
			temp.setProRightId(proright.getProRightId());
		}else{
			temp.setProRightId(proRightVO.getProRightId());
		}

		BankAccountVO bankAccount = super.bankAccountService.getCurrentBankAccountByPro(temp.getProRightId());
		if (BlankUtil.isBlank(bankAccount)) {
			if (this.canAddBankAccount(customerHouseVO)) {
				addBankAccount(customerHouseVO, temp);
			}
		} else {
			if (this.isOuted(bankAccount)) {
				// 如果银行帐号对应的托收明细状态有新建的,则表明有未回盘的数据
				long count =
					bankCollectionDao.getBankAccountCountFromCollectionDetail(bankAccount.getAccNumber(),SysrefcodeDO.FEE_COLLECTION_DETAIL_STATUZ_NEW);
				if(0l > count){
					throw new BusinessException("charge:charge_bankaccount_not_in_exception,"+bankAccount.getAccNumber(),
								BusinessException.ERROR);
				}

				super.bankAccountService.disableBankAccount(bankAccount.getKeyword(), customerHouseVO.getCreator());
				if (this.canAddBankAccount(customerHouseVO)) {
					addBankAccount(customerHouseVO, temp);
				}
			}else{
				if (this.canAddBankAccount(customerHouseVO)) {
					setBankAccountValues(customerHouseVO, temp, bankAccount);
					super.bankAccountService.editBankAccount(bankAccount);
				}else{
//					super.bankAccountService.deleteBankAccount(customerHouseVO.getHouseId());
					super.bankAccountService.disableBankAccount(bankAccount.getKeyword(), customerHouseVO.getCreator());
				}
			}
		}
	}

	/**
	 *
	 * 功能描述: 处理个人业主新增或修改
	 *
	 * @author 付湘辉
	 * Created on：2008-6-20
	 *
	 * @author
	 * Update on：
	 * 修改原因：
	 *
	 * @param sysrefcodeDO
	 * @param customerHouseVO
	 * @param customerVO
	 * @return
	 */
	private void dealIndividualOwner(SysrefcodeDO sysrefcodeDO, CustomerHouseVO customerHouseVO, CustomerVO customerVO) {
		IndividualDO individualDO=null;
		ClientDO clientDO=null;
		if(ICacheManage.ADD.equals(customerVO.getOpratorStatus())
				|| ICacheManage.EDIT.equals(customerVO.getOpratorStatus())){

			individualDO = super.dealIndividual(customerVO);

			clientDO = super.addOrEditClient(individualDO, sysrefcodeDO,customerVO.getCreator());

			this.buildClientRHouse(customerHouseVO, clientDO);

		}
	}

	/**
	 * 功能描述: 处理组织业主新增或修改
	 *
	 * @author 付湘辉
	 * Created on:2008-6-20
	 *
	 * 修改原因：
	 * @param sysrefcodeDO
	 * @param customerHouseVO
	 * @param customerVO
	 * @param clientDO
	 * @return
	 * @return ClientDO 返回结果
	 */
	private void dealOrganizationOwner(SysrefcodeDO sysrefcodeDO, CustomerHouseVO customerHouseVO, CustomerVO customerVO) {
		OrganizationDO organizationDO = null;
		ClientDO clientDO=null;
		if(ICacheManage.ADD.equals(customerVO.getOpratorStatus())
				|| ICacheManage.EDIT.equals(customerVO.getOpratorStatus())){

			organizationDO = super.dealOrgnization(customerVO);

			clientDO = super.addOrEditClient(organizationDO, sysrefcodeDO,customerVO.getCreator());

			this.buildClientRHouse(customerHouseVO, clientDO);
		}
	}

	/**
	 * 功能描述: 处理业主房屋信息的添加和修改，包括产权信息和银行帐号信息
	 *
	 * @author 付湘辉
	 * Created on:2008-6-19
	 *
	 * 修改原因：
	 * @param houseList
	 * @return void 返回结果
	 */
	private void dealOwnerHouse(List<CustomerHouseVO> houseList) {
		for (CustomerHouseVO customerHouseVO : houseList) {
			if (ICacheManage.ADD.equals(customerHouseVO.getOpratorStatus())
				|| ICacheManage.EDIT.equals(customerHouseVO.getOpratorStatus())) {
					//添加或者修改产权
				ProRightVO proRightVO=this.addOrEditProRight(customerHouseVO);

				//添加或者修改划款银行帐号
				dealBankAccount(customerHouseVO, proRightVO);
			}
		}
	}

	/**
	 * 功能描述:　判断一个划款银行帐号是否有过出盘记录 <br>
	 * @param bankAccount
	 * @return
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-9-2  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	private Boolean isOuted(BankAccountVO bankAccount){
		long count = bankCollectionDao.getBankAccountCountFromCollectionDetail(bankAccount.getAccNumber());
		return count!=0l;
	}


	/** 功能描述:  <br>
	 * @param customerHouseVO
	 * @param proRightVO
	 * @param bankAccount
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-9-2  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	*/
	private void setBankAccountValues(CustomerHouseVO customerHouseVO, ProRightVO proRightVO, BankAccountVO bankAccount) {
		bankAccount.setProRightId(proRightVO.getProRightId());
		if (!BlankUtil.isBlank(customerHouseVO.getManageHouseId())
				&& ProRightDO.CHARGE_SELECT_MERGER.equals(customerHouseVO.getChargeSelect())) {
			bankAccount.setHouseId(customerHouseVO.getManageHouseId());
		}else{
			bankAccount.setHouseId(customerHouseVO.getHouseId());
		}
		bankAccount.setBankId(customerHouseVO.getBankId());
		bankAccount.setAccNumber(customerHouseVO.getBankNumber());
		bankAccount.setAccOwner(customerHouseVO.getAccountOwner());
		bankAccount.setContactNumber(customerHouseVO.getContactNumber());
		bankAccount.setCreator(customerHouseVO.getCreator());
	}

	/**
	 * 功能描述: 执行删除业主的操作，
	 * 实质为解除业主与其房屋的关系，如果其房屋已产生费用，则不能解除
	 *
	 * @author 付湘辉
	 * Created on：2008-7-5
	 *
	 * @author
	 * Update on：
	 * 修改原因：
	 *
	 * @param sysrefcodeDO
	 * @param customerHouseVO
	 * @param customerVO
	 */
	private void toDeleteOperation(SysrefcodeDO clientTypeDO, CustomerHouseVO customerHouseVO, CustomerVO customerVO) {
		ClientDO clientDO=null;
		Long ownerId = null;
		// 检查是否已合并
		checkYetMerge(customerHouseVO);
		if (CustomerVO.INDIVIDUAL_CODE.equals(customerVO.getParticipantTypeCode())
				||CustomerVO.ORGNIZATION_CODE.equals(customerVO.getParticipantTypeCode())) {
			ownerId = customerVO.getParticipantId();
			clientDO = this.clientDao.queryClientByParticipantAndClientType(ownerId, clientTypeDO.getId());
		}else{
			throw new BusinessException("customer:participant_type_unknown_exception",
							BusinessException.ERROR);
		}

//		if (super.checkOwnerIsOnly(customerVO.getParticipantId(), customerHouseVO)) {
//			// 如果业主与房间总帐子帐已发生任何交易费用
//			super.checkUpCharge(clientDO, customerHouseVO);
//		}
		//解除一个客户与房屋的关系， 客户的家庭成员一并删除
		super.divestOneClientRHouse(clientDO, customerHouseVO,this.cur_add_owner_count);
	}

}
